package com.beans;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;

public class UserConverter implements Converter {
	public Object getAsObject(FacesContext context, UIComponent component,
			String str) throws ConverterException {
		String[] strs = str.split(",");

		User user = new User();

		try {
			user.setFirstName(strs[0]);
			user.setLastName(strs[1]);
		} catch (Exception e) {
			
			throw new ConverterException();
		}

		return user;
	}

	public String getAsString(FacesContext context, UIComponent component,
			Object obj) throws ConverterException {
		String firstName = ((User) obj).getFirstName();
		String lastName = ((User) obj).getLastName();

		return firstName + "," + lastName;
	}
}